//
//  ROLogonViewController.swift
//  NEUFOOD
//
//  Created by gray on 2017/10/19.
//  Copyright © 2017年 gray. All rights reserved.
//

import UIKit

class ROLogonViewController: UIViewController {
    @IBOutlet weak var userName: UITextField!
    
    @IBOutlet weak var passWord: UITextField!
    
    @IBAction func logon(_ sender: UIButton){
        if userName.text == ""{
           //print("用户名没有输入")
             MBProgressHUD.showDelayHUDToView(self.view, message: "用户名没有输入")
        
        }
        else{
            if passWord.text == ""{
              //print("密码没有输入")
                MBProgressHUD.showDelayHUDToView(self.view, message: "密码没有输入")}
                else{
                let RO_Logon: String = "http://60.205.189.39/userLogin.do"
                
                let parameters: NSDictionary = ["usrname":userName.text!,"userpass":passWord.text!]as NSDictionary
                let afManager = AFHTTPRequestOperationManager()
                afManager.get(RO_Logon, parameters: parameters, success: {(operation:AFHTTPRequestOperation?, responseObject:Any?) in
                  let success = (responseObject as! NSDictionary).object(forKey: "userid") as! NSString
                    if success != "0"{
                       //print("登录成功")
                        MBProgressHUD.showDelayHUDToView(self.view, message: "登录成功")
                        
                        let _ = (ACSimpleKeychain.defaultKeychain() as AnyObject).storeUsername(self.userName.text, password: self.passWord.text, identifier: "user1", forService: "userpassword")
                        
                        
                        
                        
                    }else{
                      // print("登录失败")
                         MBProgressHUD.showDelayHUDToView(self.view, message: "登录失败")
                    }
                
                }, failure: {(operation:AFHTTPRequestOperation?,error:Error?) in
                })
                }
        }
    
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
